package com.peaker.advertisingpro.db.dao

import androidx.room.*
import com.peaker.advertisingpro.bean.ProgramUrlBean

/**
 * 播放节目
 */
@Dao
interface ProgramUrlDao : BaseDao<ProgramUrlBean> {

    @Query("SELECT * FROM programdb")
    fun getProgramUrlBean(): MutableList<ProgramUrlBean>



    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(entitie: ProgramUrlBean?)

    @Delete
    fun delete(entity: ProgramUrlBean?)

    @Update
    fun update(entity: ProgramUrlBean?)

    @Query("DELETE FROM programdb")
    fun deletAll()

    /**
     * 获取节目播放次数
     * @param id String
     * @return MutableList<ProgramUrlBean>
     */
    @Query("SELECT playCount FROM programdb WHERE programId = :id")
    fun getPlayCount(id: String): Int

    /**
     * 清空播放次数
     */
    @Query("UPDATE programdb SET playCount = 0")
    fun clearPlayCount()

    /**
     * 播放次数加一
     * @param id String
     */
    @Query("UPDATE programdb SET playCount = playCount+1 WHERE programId = :id")
    fun addPlayCount(id: String)

    /**
     * 获取下载资源Id
     * @param id String
     */
    @Query("SELECT publishDetailId FROM programdb WHERE programId = :id")
    fun getPID(id: String): String

//    @Query("select * from programdb order by programId desc limit 1")
//    fun getLastData()

    /**
     * 通过Id 删除数据
     */
    @Query("DELETE  FROM programdb WHERE programId = :id")
    fun delById(id: String)

    @Query("select programId FROM programdb WHERE programId = :id")
    fun getById(id: String):String?
}